package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.CreativeTask;
import com.zjhd.sealcutting.domain.ExhibitionInfo;
import com.zjhd.sealcutting.domain.UserInfo;
import com.zjhd.sealcutting.param.CreativeTaskSearchQuery;
import com.zjhd.sealcutting.service.CreativeTaskService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.CreativeTaskVo;
import com.zjhd.sealcutting.vo.SearchResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO  创作任务管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/26 16:18
 */
@Api(value = "创作任务管理", tags = "创作任务管理")
@RequestMapping("/creativeTask")
@RestController
public class CreativeTaskController {

    private final static Logger logger = LoggerFactory.getLogger(CreativeTaskController.class);

    @Autowired
    private CreativeTaskService creativeTaskService;

    @ApiOperation(value = "分页查询创作任务列表接口", notes = "分页查询创作任务列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryCreativeTaskParamlist")
    public ResponseResult<SearchResult<CreativeTaskVo>> queryCreativeTaskParamlist(CreativeTaskSearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.queryCreativeTaskParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询创作任务列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询创作任务列表接口失败");
        }
    }

    @ApiOperation(value = "查询创作任务详情", notes = "查询创作任务详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "创作任务ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByIdDetail")
    @OperLog(operModul = "创作任务管理-查看详情",operType = "查询",operDesc = "查询创作任务详情")
    public ResponseResult queryByIdDetail(Integer id){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.queryByIdDetail(id));
        }catch (Exception ex) {
            logger.error("查询创作任务详情接口失败", ex);
            return ResultGenerator.genFailResult("查询创作任务详情接口失败");
        }
    }

    @ApiOperation(value = "创作任务投稿", notes = "创作任务投稿接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "创作任务ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "workId", value = "作品ID", dataType = "String", paramType = "query")
    })
    @PostMapping("/contributionTask")
    @OperLog(operModul = "创作任务管理-投稿",operType = "修改",operDesc = "创作任务投稿")
    public ResponseResult contributionTask(@RequestParam(value = "id",defaultValue = "")Integer id,@RequestParam(value = "workId",defaultValue = "")String workId){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.contributionTask(id,workId));
        }catch (Exception ex) {
            logger.error("创作任务投稿接口失败", ex);
            return ResultGenerator.genFailResult("创作任务投稿接口失败");
        }
    }

    @ApiOperation(value = "新增创作任务", notes = "新增创作任务接口")
    @PostMapping("/insertCreativeTask")
    @OperLog(operModul = "展览管理-新增创作任务",operType = "新增",operDesc = "新增创作任务")
    public ResponseResult insertCreativeTask(@RequestBody CreativeTask creativeTask){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.insertCreativeTask(creativeTask));
        }catch (Exception ex) {
            logger.error("新增创作任务接口失败", ex);
            return ResultGenerator.genFailResult("新增创作任务接口失败");
        }
    }

    @ApiOperation(value = "修改创作任务", notes = "修改创作任务接口")
    @PostMapping("/updateCreativeTask")
    @OperLog(operModul = "展览管理-修改创作任务",operType = "修改",operDesc = "修改创作任务")
    public ResponseResult updateCreativeTask(@RequestBody CreativeTask creativeTask){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.updateCreativeTask(creativeTask));
        }catch (Exception ex) {
            logger.error("修改创作任务接口失败", ex);
            return ResultGenerator.genFailResult("修改创作任务接口失败");
        }
    }

    @ApiOperation(value = "查询作品任务所关联的所有展览", notes = "查询作品任务所关联的所有展览接口")
    @GetMapping("/queryAllExhibition")
    @OperLog(operModul = "创作任务管理-查询作品任务所关联的所有展览",operType = "查询",operDesc = "查询作品任务所关联的所有展览")
    public ResponseResult queryAllExhibition(){
        try{
            return ResultGenerator.genSuccessResult(creativeTaskService.queryAllExhibition());
        }catch (Exception ex) {
            logger.error("查询作品任务所关联的所有展览接口失败", ex);
            return ResultGenerator.genFailResult("查询作品任务所关联的所有展览接口失败");
        }
    }
}
